<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body  class="list">
<div th:replace="include/head.html::html"></div>
<form class="layui-fluid  layui-anim-upbit layui-anim layui-form">
    <div class="layui-card">
        <!--表格中的数据 并不显示-->
        <div class="layui-card-body">
            <!--数据表格 -->
            <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="submit" value="确认">
    </div>
    <div class="layui-form-item layui-hide">
        <input type="text" name="oid" id="oid" lay-verify="oid">
        <input type="text" name="deptName" id="deptName" >
    </div>
</form>
<script type="text/javascript" th:inline="javascript">
    var editObj = null, ptable = null, treeGrid = null, tableId = 'treeTable', layer = null;
    layui.use(['jquery', 'treeGrid', 'layer','form'], function () {
        var form = layui.form;
        form.verify({
            oid: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!value){
                    return '请选择部门！';
                }
            }
        });
        var deptOid = [[${deptOid}]];
        var $ = layui.jquery;
        treeGrid = layui.treeGrid;//很重要
        layer = layui.layer;
        ptable = treeGrid.render({
            id: tableId
            , elem: '#' + tableId
            , url: 'sysDept/json'
            , cellMinWidth: 100
            , idField: 'oid'//必須字段
            , treeId: 'oid'//树形id字段名称
            , treeUpId: 'parentOid'//树形父id字段名称
            , treeShowName: 'deptName'//以树形式显示的字段
            , heightRemove: [".dHead", 0]//不计算的高度,表格设定的是固定高度，此项不生效
            , height: 'full-70'
            , isFilter: false
            , iconOpen: true//是否显示图标【默认显示】
            , isOpenDefault: true//节点默认是展开还是折叠【默认展开】
            , loading: true
            , method: 'post'
            , isPage: false
            , cols: [[//数据
                {type: 'radio'}
                , {field: 'deptName', title: '部门名称'}
            ]]
            , parseData: function (res) {//数据加载后回调
                return res;
            }
            , onClickRow: function (index, o) {
                $("#oid").val(o.oid);
                $("#deptName").val(o.deptName);
                //console.log(index,o,"单击！");
            }
            , onDblClickRow: function (index, o) {
                //console.log(index,o,"双击");
            }
            , onCheck: function (obj, checked, isAll) {//复选事件
                //console.log(obj,checked,isAll);
            }
            , onRadio: function (obj) {//单选事件
                //console.log(obj);
            }
            ,done:function (res, curr, countName) {
                treeGrid.setRadioStatus(tableId,'oid',deptOid);
            }
        });
    });

</script>
</body>
</html>
